package com.xykj.enterprise.wechat.ext.api.contacts.department;

import com.xykj.enterprise.wechat.bean.ext.BaseResp;
import com.xykj.enterprise.wechat.ext.service.contacts.ContactsDepartmentService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Function(description = "删除部门", parameters = {
        @Parameter(name = "access_token", type = Type.String, description = "access_token", required = true),

        @Parameter(name = "id", type = Type.Integer, description = "部门id", required = true),
})
@Component
public class DeleteDepartment implements Action {

    @Autowired
    private ContactsDepartmentService contactsDepartmentService;

    @Override
    public Response execute(Request request) throws Exception {
        String accessToken = request.getString("access_token");

        Integer id = request.getInteger("id");
        BaseResp rsp = contactsDepartmentService.deleteDepartment(accessToken, id);
        if (rsp.getErrcode() != 0) {
            return Response.fail(rsp.getErrmsg());
        }
        return Response.success();
    }
}
